<template>
  <transition name="main">
    <div class="wrapper" v-if="searchShow">
      <div class="top">
        <div class="icon">
          <!--suppress HtmlUnknownTarget -->
          <img alt="" :src="IconLogo" draggable="false"/>
        </div>
        <div class="close" @click="close">
          <!--suppress HtmlUnknownTarget -->
          <img alt="" :src="IconClose" draggable="false"/>
        </div>
      </div>
      <div class="search">
        <el-form :rules="rules" :model="ruleForm" ref="form" prop="email">
          <el-form-item prop="search">
            <el-input class="myInput" v-model="ruleForm.search" placeholder="商品/店铺" size="medium"
                  @keyup.enter.native="send">
              <template slot="suffix">
                <el-button type="text" @click="send" role="button">
                  <i class="el-icon-search"/>
                </el-button>
              </template>
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <keep-alive>
        <xum-good-category/>
      </keep-alive>
    </div>
  </transition>
</template>

<script>
import IconLogo from '@/assets/img/logo.png'
import IconClose from '@/assets/img/icons/close-button.svg'
import XumGoodCategory from '@/components/wrapper/part/part/XumGoodCategory'

export default {
  name: 'XumSearch',
  components: { XumGoodCategory },
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  model: {
    prop: 'visible',
    event: 'change'
  },
  data: function () {
    return {
      IconLogo,
      IconClose,
      ruleForm: {
        search: ''
      },
      rules: {},
      searchShow: false
    }
  },
  methods: {
    send () {
      if (this.ruleForm.search && this.ruleForm.search.trim().length > 0) {
        this.searchShow = false
        const search = this.ruleForm.search.trim()
        this.$router.push('/shopList/default/' + search)
      }
    },
    close () {
      this.searchShow = false
    }
  },
  watch: {
    searchShow (state) {
      this.$emit('change', state)
    },
    visible (val) {
      this.searchShow = val
    }
  }
}
</script>

<style lang="scss" scoped>

  /*进入前的效果*/
  .main-enter, .main-leave-to{
    transform: scale(.3, .3);
    opacity: 0;
  }

  /*进入中的效果*/
  .main-enter-active, .main-leave-active{
    transition: .4s;
    transition-timing-function: ease-out;
  }

  /*进入后的效果*/
  .main-enter-to, .main-leave{
    transform: scale(1, 1);
    opacity: 1;
  }

  .wrapper {
    user-select: none;
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background: #fafafa;
    z-index: 2000;

    .top {
      margin: 30px 80px;
      position: relative;

      .icon {
        position: absolute;
        top: 0;
        left: 0;
        cursor: pointer;
        user-select: none;
      }

      .close {
        position: absolute;
        top: 0;
        right: 0;
        width: 42px;
        height: 42px;
        border-radius: 50%;
        border: 2px solid #333333;
        cursor: pointer;

        img {
          height: 14px;
          width: 14px;
          margin: 13px;
        }
      }

      .close:hover {
        border-color: #888888;
      }
    }

    .search {
      margin: 100px 450px 60px;
    }

  }

</style>
